package com.ssh.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.opensymphony.xwork2.ActionSupport;
import com.ssh.entity.User;
import com.ssh.service.UserService;

public class LoginAction extends ActionSupport {
	@Autowired
	private UserService userService;
	public String login(){
		String s = null;
		HttpServletRequest request=ServletActionContext.getRequest();
		String username=request.getParameter("login_username");
		String password=request.getParameter("login_password");
		if(username.equals("") || password.equals("")){
			s="error";
		}
		List<User> list=userService.login(username, password);
		for(User user:list){
		if(user !=null){
			HttpSession session=request.getSession();
			session.setAttribute("username",username);
			s="getall";
		}else{
			s="error";
		}
		}
		return s;
	}
}
